
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;




public class Fichero {
	static String path ="/home/jripolles/prueba/";
	static FileReader fichero = null;
	BufferedReader buffer = null;
	
	public void escribir(String nombre, String cadena) throws IOException{
		FileWriter fi=new FileWriter(path+nombre,true);
		fi.write(cadena + "\r\n");
		fi.close();
	}

	public String leerTeclado() throws IOException{
		String salida;
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader buffer = new BufferedReader(input);
		salida = buffer.readLine();
		buffer.close();
		input.close();
		return salida;
	}

	public String leer(String nombre) throws IOException{
		String salida;
		if (buffer==null){
			FileReader fichero = new FileReader(path+nombre);
			buffer = new BufferedReader(fichero);
		}
		salida = buffer.readLine();
		return salida;
	}
	
	protected void finalize () throws Throwable {
	    if (fichero != null) {
	        fichero.close();
	        buffer.close();
	        fichero = null;
	        buffer = null;
	    }
	    super.finalize();
	}


}